Skip to content

Change close_account to utilize the deletion pipeline #6595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions kitsune/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,29 +452,10 @@ def test_close_account(self):
# Confirm the expected initial state.
self.assertTrue(self.user.is_active)
self.assertTrue(self.user.profile.name)
self.assertEqual(self.user.groups.count(), 1)
self.assertEqual(self.user.outbox.count(), 1)
self.assertEqual(self.user.inbox.count(), len(self.other_users))
for other_user in self.other_users:
self.assertEqual(other_user.inbox.count(), 1)
self.assertEqual(other_user.outbox.count(), 1)

res = self.client.post(reverse("users.close_account", locale="en-US"))
self.assertEqual(200, res.status_code)

self.user.refresh_from_db()

# The user should be anonymized.
self.assertTrue(self.user.username.startswith("user"))
self.assertTrue(self.user.email.endswith("@example.com"))
# The user should be deactivated, and the user's profile and groups cleared.
self.assertFalse(self.user.is_active)
self.assertFalse(self.user.profile.name)
self.assertEqual(self.user.groups.count(), 0)
# Confirm that the user's inbox and outbox have been cleared, and
# that the inbox and outbox of each of the other users remain intact.
self.assertEqual(self.user.outbox.count(), 0)
self.assertEqual(self.user.inbox.count(), 0)
for other_user in self.other_users:
self.assertEqual(other_user.inbox.count(), 1)
self.assertEqual(other_user.outbox.count(), 1)
# The user should be completely deleted
with self.assertRaises(User.DoesNotExist):
self.user.refresh_from_db()
3 changes: 1 addition & 2 deletions kitsune/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
)
from kitsune.users.templatetags.jinja_helpers import profile_url
from kitsune.users.utils import (
anonymize_user,
deactivate_user,
delete_user_pipeline,
get_oidc_fxa_setting,
Expand Down Expand Up @@ -152,7 +151,7 @@ def profile(request, username):
@login_required
@require_POST
def close_account(request):
anonymize_user(request.user)
delete_user_pipeline(request.user)

# Log the user out
auth.logout(request)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you are automatically redirect and logged out on user deletion which means that the auth.logout is redundant but it's worth confirming it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell the logout and the redirect are not automatic, and have to be purposefully called.

Expand Down